package com.lc1993929.mr.flow;

import org.apache.hadoop.mapreduce.Partitioner;

import javax.xml.soap.Text;
import java.util.HashMap;

/**
 * Created by LiuChang on 2017/11/6/006.
 */
public class ProvincePartitioner extends Partitioner<Text, FlowBean> {

    private static HashMap<String, Integer> provinceCode = new HashMap<>();

    static {
        provinceCode.put("135", 0);
        provinceCode.put("136", 1);
        provinceCode.put("137", 2);
        provinceCode.put("138", 3);
    }

    @Override
    public int getPartition(Text text, FlowBean flowBean, int numPartitions) {
        Integer code = provinceCode.get(text.toString().substring(0, 1));
        return code == null ? 4 : code;
    }
}
